import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import '../../pages/xhss/xhss_count.dart';
import '../../helper/routeHelper.dart';
import '../../pages/xhss/xhssHelper.dart';

import '../../model/xhss.dart';

class XHSSInfoPage extends StatefulWidget {
  final bool ifAppBar;
  @override
  XHSSInfoPage(this.ifAppBar);

  @override
  createState() => new XHSSInfoPageState();
}

class XHSSInfoPageState extends State<XHSSInfoPage> {
  late XHSS s1;
  late XHSS s2;
  late XHSS s3;
  late XHSS s4;
  bool IfOK = false;

  final TextEditingController c2 = new TextEditingController();

  @override
  void initState() {
    super.initState();
    //s1 = widget.s1;
    //UIData.CurrentUser!.Authority="水调值班员,电厂值班员";
    loadData();
  }

  loadData() async {
    var x1 = await XHSS.Get(0);
    var x2 = await XHSS.Get(1);
    var x3 = await XHSS.Get(2);
    var x4 = await XHSS.Get(3);

    setState(() {
      s1 = x1!;
      s2 = x2!;
      s3 = x3!;
      s4 = x4!;

      IfOK = true;
    });
  }

  @override
  Widget build(BuildContext context) {
    // if (s1 == null) return Center(child:SpinKitCircle(color: Colors.blue,));

    // TODO: implement build
    return Scaffold(
        appBar: widget.ifAppBar ? AppBar(title: Text('泄洪设施状态')) : null,
        //bottomSheet:bottomPanel2() ,
        floatingActionButton: FloatingActionButton(
            child: Icon(Icons.insert_chart),
            onPressed: () {
              RouteHelper.ShowPage(context, XHSSCountPage());
            }),
        body: IfOK == false
            ? Center(
                child: SpinKitCircle(
                color: Colors.blue,
              ))
            : SingleChildScrollView(
                child: new Container(
                    margin: EdgeInsets.only(top: 8.0),
                    child: new Column(children: <Widget>[
                      XHSSHelper.getXHSSCard(context, s1),
                      XHSSHelper.getXHSSCard(context, s2),
                      XHSSHelper.getXHSSCard(context, s3),
                      XHSSHelper.getXHSSCard(context, s4),
                    ])),
              ));
  }
}
